﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using CodeBuilder2.DBM;
using CodeBuilder2.Model;

namespace CodeBuilder2.DAL
{
    class DataAccess
    {
        /// <summary>
        /// 根据指定语句更新数据库中的内容
        /// </summary>
        /// <param name="sql">更新语句</param>
        /// <returns>在更新过程中出现的异常</returns>
        public Exception UpdateData(string sql)
        {
            Exception ex = new Exception();
            try
            {
                SqlCommand sqlCommand = new SqlCommand(sql, DBManager.SqlConn);
            }
            catch (Exception e)
            {
                ex = e;
            }
            return ex;
        }
        /// <summary>
        /// 根据指定的 sql 语句得到 DataTable
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns>查询到的 dt</returns>
        public DataTable GetDataTable(string sql)
        {
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,DBManager.SqlConn);
            DataTable dt = new DataTable();
            sqlAdapter.Fill(dt);
            return dt;
        }
        /// <summary>
        /// 根据指定的 sql 语句得到 DataSet
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns>查询到的 ds</returns>
        public DataSet GetDataSet(string sql)
        {
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql, DBManager.SqlConn);
            DataSet ds = new DataSet();
            sqlAdapter.Fill(ds);
            return ds;
        }        
    }
}
